package com.my.ddd_sample_collections.association_object.domain;

import com.my.ddd_sample_collections.association_object.south.adapter.repositories.MySubscriptionsDB;

import java.util.List;

/**
 * 这个实现是MySubscriptions的通常实现方式，所有的明细都在聚合初始化时统一加载到内存，如果明细数量特别多，就要做优化
 * @see MySubscriptionsDB
 */
public class MySubscriptionsNormal implements MySubscriptions{

    private List<Subscription> list;

    public MySubscriptionsNormal(List<Subscription> list) {
        this.list = list;
    }

    @Override
    public List<Subscription> subList(int from, int to) {
        return list.subList(from, to);
    }

    @Override
    public double getTotalSubscriptionFee() {
        double sum = 0;
        for (int i = 0; i < list.size(); i++) {
            sum += list.get(i).getFee();
        }
        return sum;
    }

    @Override
    public int count() {
        return list==null?0:list.size();
    }
}
